var c = require('checkAuthority');
var customsDeclaration, cabinetNo, fenghaoNo, trailerCost, otherCost, customsDeclarationCost, trailerPayCost, customsDeclarationPayCost;

var addDeclareTemplate = __inline('addDeclare.handlebars');
$('#addDeclareForm').html(addDeclareTemplate);

$('#trailerCost').val(0);
$('#otherCost').val(0);
$('#customsDeclarationCost').val(0);
$('#trailerPayCost').val(0);
$('#customsDeclarationPayCost').val(0);

$('#fenghaoNo').blur(function() {
	customsDeclaration = $('#customsDeclaration').val();
	cabinetNo = $('#cabinetNo').val();
	fenghaoNo = $(this).val();
/*	trailerCost = $('#trailerCost').val();
	otherCost = $('#otherCost').val();
	customsDeclarationCost = $('#customsDeclarationCost').val();
	trailerPayCost = $('#trailerPayCost').val();
	customsDeclarationPayCost = $(this).val();*/

	checkA();
});

yuki.check('trailerCost');
yuki.check('otherCost');
yuki.check('customsDeclarationCost');
yuki.check('trailerPayCost');
yuki.check('customsDeclarationPayCost');

function checkA(){
	if (customsDeclaration != "" && cabinetNo != "" && fenghaoNo != ""  && $('.error-tip').css('display') == 'none') {
		$('#addDeclareForm button[type=submit]').removeAttr('disabled');
	} else {
		$('#addDeclareForm button[type=submit]').attr('disabled', 'disabled');
	}
}

$('#addDeclareForm button[type=submit]').on('click', function() {
	$.ajax({
		type: "post",
		url: "./order/addorder.bto",
		async: true,
		cache: false,
		data: $('#addDeclareForm').serialize(),
		success: function(data) {
			var authorityCode = data.code;
			function template() {
				alert('录入成功！');
				window.location.href = "declareManage.html";
			}
			c.authority(authorityCode, template);
		}
	});
});
